<?php if (!defined('SERVER_ROOT')) exit('No direct script access allowed');

class tochuyenmon_Controller extends Controller {

    function __construct(){
        parent::__construct('qlcb', 'tochuyenmon');
        $this->check_login();
        $this->view->template->menu_html =$this->CREATE_MENU();
        $this->view->template->nhacviec_html =$this->CREATE_NHAC_VIEC(); 
        $this->CHECK_QUYEN('qlcb', 'tochuyenmon');
    }

    function main(){
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $this->dsp_all_tochuyenmon();
    }
    private function _save_filter(){
        $v_MA_DON_VI_filter        = $this->get_post_var('cbx_MA_DON_VI_filter');
        return array(
            'cbx_MA_DON_VI_filter'        => $v_MA_DON_VI_filter
        );
    }
    function dsp_all_tochuyenmon(){
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $arr_filter = $this->_save_filter();
        $VIEW_DATA['arr_filter']                 = $arr_filter;
        $VIEW_DATA['arr_all_tochuyenmon']        = $this->model->qry_all_tochuyenmon_filter($arr_filter);
        $VIEW_DATA['arr_all_donvi_filter']       = $this->model->SELECT_DONVI_tatca();
        $VIEW_DATA['arr_all_TR_TO_CHUYEN_MON']       = $this->model->SELECT_TO_CHUYEN_MON_ALL_TR($arr_filter);
        $this->view->render('dsp_all_tochuyenmon', $VIEW_DATA);
    }
    function dsp_all_tochuyenmon_dv(){
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $v_m                      = trim(get_request_var('m'));
        $VIEW_DATA['var_madonvi'] = $v_m;
        $VIEW_DATA['arr_single_donvi'] = $this->model->qry_single_donvi($v_m);
        $VIEW_DATA['arr_all_TR_TO_CHUYEN_MON']       = $this->model->SELECT_TO_CHUYEN_MON_ALL_TR2($v_m);
        $this->view->render('dsp_all_tochuyenmon_dv', $VIEW_DATA);
    }
    public function dsp_single_tochuyenmon($MA_TO_CHUYEN_MON){
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $MA_TO_CHUYEN_MON = replace_bad_char($MA_TO_CHUYEN_MON);
        $VIEW_DATA['arr_single_tochuyenmon'] = $this->model->qry_single_tochuyenmon($MA_TO_CHUYEN_MON);
        $VIEW_DATA['arr_all_donvi'] = $this->model->SELECT_DONVI_nothing();
        $this->view->render('dsp_single_tochuyenmon', $VIEW_DATA);
    }
    public function update_tochuyenmon(){
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $this->model->goback_url = $this->view->get_controller_url() . 'dsp_all_tochuyenmon';
        $this->model->update_tochuyenmon();
    }
    public function delete_tochuyenmon(){
        (Session::get(TIEP_DAU_NGU_SESSION.'QUAN_TRI') == 1) Or die($this->access_denied());
        $this->model->goback_url = $this->view->get_controller_url() . 'dsp_all_tochuyenmon';
        $this->model->delete_tochuyenmon();
    }

}